package edu.cs335pl.questionnaire.util;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;

import com.itextpdf.kernel.color.Color;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;
import com.itextpdf.text.pdf.draw.LineSeparator;

public class ReportDemo {
    //字体
    private static Font titleFont = FontFactory.getFont(FontFactory.HELVETICA, 18f, Font.BOLD, new BaseColor(112, 173, 71));
    private static Font subTitleFont = FontFactory.getFont(FontFactory.TIMES_BOLD, 15f, Font.NORMAL, new BaseColor(134, 195, 65));
    private static Font contentFont = FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.NORMAL, new BaseColor(96, 95, 95));
    //分数
    private static int[] scoreList = {200,300,100,200,300,100,200,100,100,200,100,200,100,200};


    public static void main(String[] args) throws IOException, DocumentException {

        // 1.新建document对象
        Rectangle pageSize = PageSize.A4;
        Document document = new Document(pageSize, 40, 40, 50, 50);
        // 2.建立一个书写器(Writer)与document对象关联，通过书写器(Writer)可以将文档写入到磁盘中。
        // 创建 PdfWriter 对象 第一个参数是对文档对象的引用，第二个参数是文件的实际名称，在该名称中还会给出其输出路径。
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("D:/读书▲/CS335 Software Engineering and Software Process/PDF文件/ReportDemo.pdf"));

        // 3.打开文档
        document.open();

        //设置属性
        //标题
        document.addTitle("this is a title");
        //作者
        document.addAuthor("H__D");
        //主题
        document.addSubject("this is subject");
        //关键字
        document.addKeywords("Keywords");
        //创建时间
        document.addCreationDate();
        //应用程序
        document.addCreator("hd.com");

        //4.添加内容

        //logo
        Image logo = Image.getInstance("https://albatel.ie/wp-content/uploads/2021/03/new-logo.jpg");
        //设置图片的宽度和高度
        logo.scaleAbsolute(385f, 152f);
        logo.scalePercent(30);
        //设置图片位置的x轴和y轴
        logo.setAbsolutePosition(pageSize.getWidth() - (logo.getWidth() * 0.3f) - 30f, pageSize.getHeight() - (logo.getHeight() * 0.3f) - 40f);
        //将图片1添加到pdf文件中
        document.add(logo);

        //标题
        Paragraph title = new Paragraph("Human Resource Health Check Report", titleFont);
        title.setAlignment(Element.ALIGN_LEFT);
        document.add(title);

        //画线
        Paragraph p1 = new Paragraph();
        LineSeparator ls = new LineSeparator(1f, 100, new BaseColor(182, 218, 139), Element.ALIGN_CENTER, 0f);
        p1.add(new Chunk(ls));
        document.add(p1);

        //副标题
        Paragraph[] subTitle = new Paragraph[13];
        String subTitleList =
                "Legal Compliance" + "\n"
                        + "Hours of Work and Leave" + "\n"
                        + "Policies & Practices" + "\n"
                        + "Employee Relations" + "\n"
                        + "Performance Management" + "\n"
                        + "Training and Development" + "\n"
                        + "Recruitment & Retention" + "\n"
                        + "Change and Reorganisation" + "\n"
                        + "Pay and Benefits" + "\n"
                        + "Employee Communication & Engagement" + "\n"
                        + "Health and Safety" + "\n"
                        + "Covid Related" + "\n"
                        + "Employee Records and GDPR";
        Scanner subTitleSc = new Scanner(subTitleList);
        for (int i = 0; i < 13; i++) {
            subTitle[i] = new Paragraph(subTitleSc.nextLine(), subTitleFont);
            subTitle[i].setIndentationLeft(10f);
            subTitle[i].setAlignment(Element.ALIGN_LEFT);
        }

        //生成报告
        for(int i = 0;i<13;i++){
            //副标题;
            document.add(subTitle[i]);
            //分类分析结果
            document.add(analysis(i+1,scoreList[i]));
        }

        // 5.关闭文档
        document.close();
    }

    public static Paragraph analysis(int partId, int score) {
        Paragraph paragraph = new Paragraph();
        paragraph.setFont(contentFont);
        paragraph.setLeading(16f);
        paragraph.setSpacingBefore(2f);
        paragraph.setSpacingAfter(5f);
        paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
        int identationLength = 10;
        paragraph.setIndentationLeft(identationLength);
        paragraph.setIndentationRight(identationLength);

        if (partId == 1) {
            if (score <= 200) {
                paragraph.add("This means that your company has big problems in the most basic aspects of hiring employees, " +
                        "such as failing to comply with relevant legal treaties, " +
                        "and your company needs to make timely corrections or improve relevant employment terms and paper contracts to ensure The normal operation of the company." + "\n" +
                        "We recommend a legal information website: " + "\n" + "https://www.66law.cn/question/27222064.aspx, you can also consult your lawyer");
            } else if (score <= 399) {
                paragraph.add("This means that your company may meet the legal requirements for hiring employees, but there are problems of indirect discrimination or lack of appendices, etc., " +
                        "and your company needs to make rectifications and improve relevant materials in a timely manner to ensure that the recruitment method, " +
                        "salary and The reward plan guarantees that all employees are treated equally, and the employment terms cover all situations."
                        + "\n" +
                        "We recommend an employment contract template website: " + "\n" +
                        "http://360ppt.botui.ink/wordmuban/hetong.html?plan=105-2848-1216407, " + "\n" +
                        "and also recommend a book to you: \"Employment Contract\".");
            } else if (score == 400) {
                paragraph.add("Congratulations! Your company has done very well in the basic aspect of hiring employees' laws and compliance!");
            }
        }
        if (partId == 2) {
            if (score <= 200) {
                paragraph.add("This means that your company’s employees have not been given the right to leave under the law or have not received a break time commensurate with the intensity of their work. " +
                        "Your company needs to establish a related vacation system to ensure employees' basic vacation rights, and at the same time ensure that employees' motivation and efficiency at work are not affected.");
            } else if (score <= 399) {
                paragraph.add("This means that your company’s vacation system meets the legal requirements, but it can still be further improved or lack of records of working hours. " +
                        "We recommend that your company make relevant adjustments to ensure a better understanding of employees’ work conditions. Combination of work and rest for employees.");
            } else if (score == 400) {
                paragraph.add("Congratulations! Your company has done a great job in employee vacations!");
            }
        }
        if (partId == 3) {
            if (score <= 200) {
                paragraph.add("This means that your company has a big problem with policies. Your company does not have a complete and detailed employee manual or lacks an equal opportunity policy." +
                        " This set of manuals will be used to provide correct responses to bad incidents such as bullying and harassment, " +
                        "stipulate measures to protect company secrets, and provide countermeasures in the face of flexible work needs. " +"\n"+
                        "We promote a website that provides template reference for you: " + "\n" +
                        "http://office.iask.com/search.html?cond=%E5%91%98%E5%B7%A5%E6%89%8B%E5%86%8C%E5%92%8C%E8%A7%84%E7%AB%A0%E5%88%B6%E5%BA%A6&utm_source=360bg02&utm_medium=rs&utm_campaign=ygsc-gzzd&utm_term=ygschgzzd&qhclickid=23440d82074a210d");
            } else if (score <= 499) {
                paragraph.add("This means that your company has formulated an employee handbook and has an equal opportunity policy, but the content of the employee handbook can still be further improved, " +
                        "such as social media policies, confidentiality agreements, intellectual property");
            } else if (score == 500) {
                paragraph.add("Congratulations! Your company has done very well in policy formulation!");
            }
        }
        if (partId == 4) {
            if (score <= 100) {
                paragraph.add(" This means that your company’s employee relations have a big problem, there are more employee disputes and dissatisfaction, and the manager does not have enough ability to deal with it." +
                        "We recommend that your company train managers on employee relationship management. " +
                        "In addition, we also recommend that your company improve the reward mechanism such as benefits and benefits to improve corporate cohesion.");
            } else if (score <= 299) {
                paragraph.add("This means that your company’s employee relations are good, but there is still room for improvement." +
                        " We recommend that your company regularly organize team building activities, such as dinners and networking activities, to promote employee relations.");
            } else if (score == 300) {
                paragraph.add("Congratulations! This means that your company is very cohesive!");
            }
        }
        if (partId == 5) {
            if (score <= 300) {
                paragraph.add(" This means that your company has many problems in performance management. " +
                        "We recommend that your company provide simple induction training before employees start their jobs to let them know their job characteristics " +
                        "and responsibilities and establish a complete and objective evaluation The process of employee performance, " +
                        "regular inspections and feedback on probationary employees and regular employees.");
            } else if (score <= 599) {
                paragraph.add("This means that your company has a process for evaluating employee performance but there are still many areas that need to be improved, " +
                        "or it means that your company has long-term unresolved issues or internal disciplinary issues. " +
                        "We recommend that your company address Make corresponding adjustments to the problems, " +
                        "and formulate relevant rewards and punishments to reward high-performing employees and punish employees with disciplinary problems.");
            } else if (score == 600) {
                paragraph.add("Congratulations! Your company has done a good job in performance management!");
            }
        }
        if (partId == 6) {
            if (score <= 100) {
                paragraph.add(" This means that your company cannot well identify the skill gaps and development needs between employees, and the direct managers have not received training to deal with personnel issues. " +
                        "We recommend that your company regularly inspect the skills of employees and train direct managers.");
            } else if (score <= 199) {
                paragraph.add("This means that there is still room for improvement in the skills of your company’s employees and managers. We recommend that your company provide regular skills training");
            } else if (score == 200) {
                paragraph.add("Congratulations! Your company has done a good job in training and development.");
            }
        }
        if (partId == 7) {
            if (score <= 200) {
                paragraph.add("This means that your company has big problems in hiring and retaining employees. " +
                        "Your company does not have a clearly structured onboarding process. " +
                        "You and your manager lack skills in interview selection and the company cannot obtain With enough high-quality employees, " +
                        "we recommend that you and your manager receive professional training in selection techniques, or hire a professional personnel manager to help your company recruit talents and establish a complete and clear entry process." +
                        " The success of recruitment means selecting the right employees, which can also increase the chances of employees staying.");
            } else if (score <= 499) {
                paragraph.add("This means that your company’s employee turnover rate is high. " +
                        "We recommend that your company conduct research and surveys to find out the common reasons for employee turnover," +
                        " such as low salary or unsatisfactory working environment. " +
                        "After investigation, make corresponding adjustments to the reasons.");
            } else if (score == 500) {
                paragraph.add("Congratulations! Your company has done a great job hiring and retaining employees!");
            }
        }
        if (partId == 8) {
            if (score <= 100) {
                paragraph.add("This means that your company lacks a strong policy to manage sluggish employees and resolve potential layoffs. " +
                        "We recommend that you carefully understand the rules on handling business restructuring in the Labor Law, " +
                        "and formulate relevant policies to deal with business downturns based on the actual situation of the company.");
            } else if (score <= 199) {
                paragraph.add("This means that there is still room for improvement in your company's ability to respond to changes and carry out business restructuring. " +
                        "We recommend that your company establish a business reward mechanism, issue rules, " +
                        "and implement rewards or penalties based on employees’ business conditions.");
            } else if (score == 200) {
                paragraph.add("Congratulations! Your company can respond well to changes and restructuring.");
            }
        }
        if (partId == 9) {
            if (score <= 200) {
                paragraph.add("This means that your company has a big problem in terms of wages and benefits, " +
                        "and lacks the process of evaluating and reviewing employees' salaries and benefits. " +
                        "Employees' salaries may not meet the requirements of national laws or get equal and fair wages. " +
                        "Your company needs to establish a complete salary and welfare system to ensure that salary and reward plans are not discriminatory, " +
                        "and that the minimum wage for employees meets national legal requirements.");
            } else if (score <= 499) {
                paragraph.add("This means that your company's salary and welfare system meets the legal requirements, " +
                        "but it can still be further improved. We recommend that your company develop a process for assessing and reviewing " +
                        "employee salaries and benefits to ensure fair and just payment of salaries and benefits to every employee.");
            } else if (score == 500) {
                paragraph.add("Congratulations! Your company has done a good job in wages and benefits!");
            }
        }
        if (partId == 10) {
            if (score <= 200) {
                paragraph.add("This means that your company’s employees do not understand the company’s macro development trends, " +
                        "and only complete their assigned tasks, which is not conducive to enhancing employees’ sense of belonging to the company. " +
                        "We recommend that your company hold regular work meetings to familiarize employees with business development (for example: financial performance, upcoming changes)");
            } else if (score <= 299) {
                paragraph.add("This means that the communication between your company and employees still needs to be strengthened. " +
                        "We suggest that your company organizes seminars on a regular basis to listen to their opinions on recent work. We also recommend that your company conduct a quarterly employee engagement survey.");
            } else if (score == 300) {
                paragraph.add("Congratulations! This means that your company is doing a good job of communicating with employees!");
            }
        }
        if (partId == 11) {
            if (score <= 100) {
                paragraph.add("This means that your company has a big problem in terms of safety and health." +
                        " We recommend that your company formulate a health and safety policy, " +
                        "and promptly investigate and report when accidents, near misses, injuries and diseases occur in the workplace , " +
                        "To ensure the physical health of employees.");
            } else if (score <= 299) {
                paragraph.add("This means that your company still has room for improvement in terms of safety and health." +
                        " We recommend that your company organize employees to conduct health checkups every year to investigate potential safety hazards in the workplace.");
            } else if (score == 400) {
                paragraph.add("Congratulations! This means that your company is doing a good job of security!");
            }
        }
        if (partId == 12) {
            if (score <= 300) {
                paragraph.add("This means that your company has problems with the prevention and control of the new crown epidemic." +
                        " We recommend that your company appoint a chief worker representative and conduct a risk assessment on the homework station of remote employees");
            } else if (score == 300) {
                paragraph.add("Congratulations! This means that your company has done a good job in the prevention and control of the new crown epidemic!");
            }
        }
        if (partId == 13) {
            if (score <= 100) {
                paragraph.add(" This means that your company has a big problem with data security. " +
                        "We recommend that your company formulate a data protection policy that complies " +
                        "with the Data Protection Act of 2018, keep complete records of employees, " +
                        "and destroy them safely. Any data that is no longer needed.");
            } else if (score <= 299) {
                paragraph.add("This means that your company still has room for improvement in data security. " +
                        "We recommend that your company sign a data protection agreement with your employees " +
                        "so that every employee can consciously participate in the company's data protection.");
            } else if (score == 300) {
                paragraph.add("Congratulations! This means that your company is doing a good job of data security!");
            }
        }
        return paragraph;
    }


}